package com.zhw.cloud.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class SystemService {
	@Autowired
	private RestTemplate restTemplate;
	/**
	 * 通过RestTemplate，调用在eureka注册的服务器，请求的url为spring.application.name配置的项目名调用
	 * EUREKA-CLIENT-1 就是服务提供者，在eureka中注册的服务名
	 * @return
	 */
	@HystrixCommand(fallbackMethod = "getNameError")
	public String getName() {
		return restTemplate.getForObject("http://EUREKA-CLIENT-1/getName.do", String.class);
	}
	public String getNameError() {
		return "ribbon:sorry,eurekaClient is closed!";
	}
}
